/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package model;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author km
 */
@Entity
@Table(name = "CREDIT_CARD")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "CreditCard.findAll", query = "SELECT c FROM CreditCard c"),
    @NamedQuery(name = "CreditCard.findByCreditCardId", query = "SELECT c FROM CreditCard c WHERE c.creditCardId = :creditCardId"),
    @NamedQuery(name = "CreditCard.findByCcv", query = "SELECT c FROM CreditCard c WHERE c.ccv = :ccv"),
    @NamedQuery(name = "CreditCard.findByCardNumber", query = "SELECT c FROM CreditCard c WHERE c.cardNumber = :cardNumber"),
    @NamedQuery(name = "CreditCard.findByOwnerName", query = "SELECT c FROM CreditCard c WHERE c.ownerName = :ownerName"),
    @NamedQuery(name = "CreditCard.findByValid", query = "SELECT c FROM CreditCard c WHERE c.valid = :valid")})
public class CreditCard implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "CREDIT_CARD_ID")
    private Integer creditCardId;
    @Basic(optional = false)
    @Column(name = "CCV")
    private int ccv;
    @Basic(optional = false)
    @Column(name = "CARD_NUMBER")
    private String cardNumber;
    @Basic(optional = false)
    @Column(name = "OWNER_NAME")
    private String ownerName;
    @Column(name = "VALID")
    private Serializable valid;
    @OneToMany(mappedBy = "creditCard")
    private List<Customer> customerList;
    @JoinColumn(name = "BANK", referencedColumnName = "BANK_ID")
    @ManyToOne(optional = false)
    private Bank bank;

    public CreditCard() {
    }

    public CreditCard(Integer creditCardId) {
        this.creditCardId = creditCardId;
    }

    public CreditCard(Integer creditCardId, int ccv, String cardNumber, String ownerName) {
        this.creditCardId = creditCardId;
        this.ccv = ccv;
        this.cardNumber = cardNumber;
        this.ownerName = ownerName;
    }

    public Integer getCreditCardId() {
        return creditCardId;
    }

    public void setCreditCardId(Integer creditCardId) {
        this.creditCardId = creditCardId;
    }

    public int getCcv() {
        return ccv;
    }

    public void setCcv(int ccv) {
        this.ccv = ccv;
    }

    public String getCardNumber() {
        return cardNumber;
    }

    public void setCardNumber(String cardNumber) {
        this.cardNumber = cardNumber;
    }

    public String getOwnerName() {
        return ownerName;
    }

    public void setOwnerName(String ownerName) {
        this.ownerName = ownerName;
    }

    public Serializable getValid() {
        return valid;
    }

    public void setValid(Serializable valid) {
        this.valid = valid;
    }

    @XmlTransient
    public List<Customer> getCustomerList() {
        return customerList;
    }

    public void setCustomerList(List<Customer> customerList) {
        this.customerList = customerList;
    }

    public Bank getBank() {
        return bank;
    }

    public void setBank(Bank bank) {
        this.bank = bank;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (creditCardId != null ? creditCardId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof CreditCard)) {
            return false;
        }
        CreditCard other = (CreditCard) object;
        if ((this.creditCardId == null && other.creditCardId != null) || (this.creditCardId != null && !this.creditCardId.equals(other.creditCardId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "model.CreditCard[ creditCardId=" + creditCardId + " ]";
    }
    
}
